﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;

namespace MicropleSoft.WmsApp.Library.Common
{
    public class LocalBaseDataWrapBuilderFactory
    {
        private const string PrixResources = "MicropleSoft.WmsApp.Library.Common.LocalBaseDataFile";
        private static bool _isBuild = false;
        public static void BuildLocalBaseData()
        {
            if (!_isBuild)
            {
                //先加载资源文件，所有的xml文件
                //然后循环每个资源文件，构造Wrap对象，放入缓存
                //从嵌入资源内读取 xml 
                Assembly asm = Assembly.GetExecutingAssembly();//读取嵌入式资源
                string[] resources = asm.GetManifestResourceNames();
                foreach (var resource in resources)
                {
                    if (resource.StartsWith(PrixResources))
                    {
                        Stream stream = asm.GetManifestResourceStream(resource);
                        CreateLocalBaseDataWrapBuilder().BuildBaseDataWrap(resource.Replace(PrixResources + ".", ""),
                                                                           stream);
                    }
                }
        
                _isBuild = true;
            }
        }

        public static ILocalBaseDataWrapBuilder CreateLocalBaseDataWrapBuilder()
        {
            return new LocalBaseDataWrapBuilder();
        }
    }
}
